﻿<cfsilent>
	<cfscript>
		
		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
	
		taskProp = getProperty("serviceFactory").getBean("taskPropertyAdvice");
		
		response = structNew();
		structInsert(response, "success", false, true);
		
		examId = event.getArg("EXID");
		
		transaction {
			
			/* 加载考试任务 */
			sql = "SELECT 
						t_examtask.task_prog, 
						t_examtask.term_id, 
						t_examtask.exidx, 
						t_examtask.cid 
					FROM 
						t_examtask 
					WHERE 
						t_examtask.task_exid = :taskExid ";
						
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskExid", value=examId, cfsqltype="cf_sql_char" );
			rs_examTask = queryObj.execute( sql=sql ).getResult();
			
			if ( rs_examTask.task_prog eq "2" ) {
				
				/* 更新考试状态为已发布 */
				sql = "UPDATE t_examtask SET task_prog = :taskProg WHERE task_exid = :taskExamId ";
				 
				queryObj = new query( datasource=application.dnsMaster ); 
				queryObj.addParam( name="taskProg", value="3", cfsqltype="cf_sql_char" ); 
				queryObj.addParam( name="taskExamId", value=examId, cfsqltype="cf_sql_char" ); 
				queryObj.execute( sql=sql );
	
				/* 同时更新这些教学任务 标志为禁止学生选课 禁止学生退课 */

				termId = rs_examTask.term_id;
				examIdx = rs_examTask.exidx;
				courseId = rs_examTask.cid;

				/* 获取考试的教学班列表 */
				sql = "SELECT task_id, task_type FROM t_examplan 
						WHERE cid = :courseId 
							  AND 
							  term_id = :termId 
							  AND 
							  exidx = :examIndex "; 
				
				queryObj = new query( datasource=application.dnsMaster ); 
				queryObj.addParam( name="courseId", value=courseId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="examIndex", value=examIdx, cfsqltype="cf_sql_char" );
				rs_taskIds= queryObj.execute( sql=sql ).getResult(); 
					
				for ( i=1; i LTE rs_taskIds.recordCount; i++){ 
					
					taskId = rs_taskIds["task_id"][i];
					taskType = rs_taskIds["task_type"][i];

					/* 载入教学任务 */
					switch(taskType){
						case "C":
							sql = "SELECT task_prop FROM t_common_task WHERE tsk_id = :taskId ";
							
							break;
			
						case "P":
							sql = "SELECT task_prop FROM t_task WHERE tsk_id = :taskId ";
							
							break;
						
						case "R":
							sql = "SELECT task_prop FROM t_reopen_task WHERE tsk_id = :taskId ";
							
							break;
						
						case "T":
							sql = "SELECT task_prop FROM t_sport_task WHERE tsk_id = :taskId ";
							
							break;
					}
					queryObj = new query( datasource=application.dnsMaster );
					queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
					rs_task = queryObj.execute( sql=sql ).getResult();
					
					if ( rs_task.recordCount ) {
						
						taskProp.parseProperty( rs_task.task_prop );
						
						/* 设置教学任务禁止学生选课 即不可新增学生 */
						taskProp.setSubscribe(true);
						/* 设置禁止学生退课 即学生不可退选课程 */
						taskProp.setDischarge(true);
						
						switch (taskType) {
								
							case "C":
								sql = "update t_common_task SET task_prop = :taskProp WHERE tsk_id = :taskId ";
								
								break;
				
							case "P":
								sql = "update t_task SET task_prop = :taskProp WHERE tsk_id = :taskId ";
								
								break;
							
							case "R":
								sql = "update t_reopen_task SET task_prop = :taskProp WHERE tsk_id = :taskId ";
								
								break;
							
							case "T":
								sql = "update t_sport_task SET task_prop = :taskProp WHERE tsk_id = :taskId ";
								
								break;
						}
						queryObj = new query( datasource=application.dnsMaster );
						queryObj.addParam( name="taskProp", value=taskProp.stringProperty(), cfsqltype="cf_sql_varchar" );
						queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
						queryObj.execute( sql=sql );

					}
					
				}
				
				
				structInsert(response, "success", true, true);
				
			}
			else {
				
				structInsert(response, "ExamID", examId, true);
				structInsert(response, "reason", "考试状态异常 未完成时间、地点编排", true);
				
			}
			
		}
		
	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>